<template>
    <div class="contract-list-page ContractReissueList">
        <Card>
            <div class="form">
                <revoke-handle-form
                    :formValidate="formValidate"
                    :loading="loading"
                    @getList="getList"
                    :dataDict="dataDict"
                />
            </div>
            <div class="table">
                <revoke-handle-table
                    :formValidate="formValidate"
                    :loading="loading"
                    :dataDict="dataDict"
                    :contractTable="contractTable"
                    @getList="getList"
                    @createCase="createCase"
                    @showContractDetial="showContractDetial"
                />
            </div>
            <revokeCase
                :contractBusiness="contractBusiness"
                :handleBusiness="'revokeHandle'"
                :dataDict="dataDict"
                :isSP="isSP"
                :modal="modal"
                :modalTitle="modalTitle"
                @showContractDetial="createRevoke"
                @closeModal="closeModal"
            />
        </Card>
    </div>
</template>
<script>
    import {mapGetters} from "vuex";
    import {
        getManageRevokeHandleList,
    } from "_p/basic/api/contract/revoke/revoke-handle";
    import {channelType} from "_p/basic/api/contract/channel-type/channel-type";
    import {getDictDataList} from "_p/basic/assets/contract/js/utils";
    import RevokeHandleForm from "./revokeHandleForm";
    import revokeHandleTable from "./revokeHandleTable";
    import revokeCase from "./revoke-case/index";

    export default {
        name: "revoke-handle",
        components: {RevokeHandleForm, revokeHandleTable,revokeCase},
        props: {
            sourceType: {
                type: Array,
                required: true
            },
        },
        data() {
            return {
                pageNo: 1,
                isSP: true,
                dicttArr: ["loanModel", "PersonRoleType", "processStatus", "receiptSourceType","bankCode"],
                dataDict: {
                    treatmentMethodDict:[{title:"收入",value: 'INCOME'},{title:'退款',value:'REFUND'}]
                },
                loading: false,
                // 日期区间
                isDateErr: false,
                endTime: "",
                //新增窗口开关控制
                modal: false,
                modalTitle: "",
                operationLoading: false,
                //互斥业务
                contractBusiness:["revokeHandle"],
                formValidate: {
                    applyNo: "", // 申请编号
                    caseNo: "", // 案件编号
                    contactNo: "", // 联系方式
                    contractNo: "", // 合同号
                    startTime: "", //	string($date-time) // 申请时间
                    custName: "", // 客户姓名
                    endTime: "", //	string($date-time) // 结束时间
                    id: "", // id
                    pageNumber: 1, // integer($int32) // 当前页
                    pageSize: 50, //integer($int32) // 多少条
                    treatmentMethod: "", // 处理方式
                    processStatus: null // 处理状态
                },
                ruleInline: {},
                contractTable: {
                    current: 1, // 表格当前页
                    pages: 0,
                    searchCount: false,
                    size: 10,
                    total: 0,
                    orders: [],
                    records: []
                },
                pageSizeOpts: [10, 20, 50, 100],
                // selct 数据字典
                processModeDict: []
            };
        },
        computed: {
            ...mapGetters({userInfo: "userInfo", roleType: "roles"}),

        },
        created() {
            this.isSP = channelType(this.$route.meta.params);
        },
        mounted() {
            console.group("初始数据：");
            console.log("userInfo:", this.userInfo);
            console.log("pageParams:", this.pageParams);
            console.log("roleType:", this.roleType);
            console.log("isApprove:", this.isApprove);
            console.log("contractNo:", this.contractNo);
            console.groupEnd();
            this.init();
            this.getRevokeHandle()
        },
        activated() {
            this.init();
        },
        methods: {
            init() {
                this.getDictDataList();
            },
            getDictDataList() {
                getDictDataList(this.dicttArr).then(res => {
                    console.group("数据字典:");
                    console.log(this.dicttArr.join("  "));
                    console.log(JSON.parse(JSON.stringify(res)));
                    console.groupEnd();
                    this.dataDict = res;
                    this.dataDict.treatmentMethodDict=[{title:"收入",value: 'INCOME'},{title:'退款',value:'REFUND'}];

                });
            },
            getList(data) {
                data.sourceType=this.sourceType;
                getManageRevokeHandleList(data).then(res => {
                    console.log(res.data);
                    this.loading = false;
                    if (res.code === "0000") {
                        this.contractTable = res.data;

                    } else {
                        this.$Message.error("Fail!");
                    }
                });
            },
            getRevokeHandle(){
                this.getList(this.formValidate);
            },
            // 分页 Fn
            changePageSize(num) {
                this.getList(
                    Object.assign({}, this.formValidate, {pageSize: num})
                );
                this.formValidate.pageSize = num;
            },
            changePage(num) {
                this.getList(
                    Object.assign({}, this.formValidate, {pageNumber: num})
                );
                this.formValidate.pageNumber = num;
            },
             showContractDetial(params,type) {
                if (!params && !params.contractNo) return;
                params.type = type;
                params.editFlag = true;
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/revoke-handle/revoke-contact-detial/index",
                    "收款撤销结果处理",
                    "ios-add",
                    params,
                    "revoke-detial-" + this.pageNo,
                    [],
                    true
                );
                this.pageNo += 1;
            },
            createRevoke(params,type) {
                params.type = type;
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/revoke-handle/revoke-contact-detial/index",
                    "收款撤销结果处理",
                    "ios-add",
                    params,
                    "revoke-detial-" + params.contractNo,
                    [],
                    true
                );
            },
            // 弹窗
            createCase() {
                this.modalTitle = "已收款撤销列表";
                this.modal = true;
            },
            closeModal() {
                this.modal = false;
            },
        }

    };
</script>
<style lang="less">
    @import "../../../../styles/common/form.less";

    .ContractReissueList {
        .table {
            padding-top: 16px;
        }
    }
</style>
